/****************************init*************/
function queryTask_task(page) {
	sys_loading();
	var type = $('#task_type').val();
	var parm = null
	if ('1' == type) {
		parm = $('#queryTaskForm').serialize() + (page != null ? ('&page=' + page) : '');
	} else if ('2' == type) {
		parm = $('#queryTransferForm').serialize() + (page != null ? ('&page=' + page) : '');
	}
	var url = create_url('task-query');
	sys_record_parm('task',parm);
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_loading_close();
			if ('1' == type) {
				$('#taskResultList').html(result);
			} else if ('2' == type) {
				$('#transferResultList').html(result);
			}
		}
	});
}

function queryTransfer_task(page){
	sys_loading();
	var parm = $('#queryTransferForm').serialize() + (page != null ? ('&page=' + page) : '');
	var url = create_url('task-query');
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_loading_close();
			$('#transferResultList').html(result);
		}
	});
}

function editTask_task(code) {
	var parm = {'code':code};
	var url = create_url('task-edit');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm});
}

function deleteTask_task(code, title) {
	var url = create_url('task-delete');
		$.Zebra_Dialog('要删除 《' + title + '》 任务吗?',{
		'type': 'question',
		'title': '警告' ,
		'buttons':[
	           {caption:'确认',callback:function() {
	        	   aidExecuteTask_task(code, url);
	    		}},
	           {caption:'取消',callback:function(){}
	    	}]
	});
}

function aidExecuteTask_task(code, url) {
	var parm = {'code':code};
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if ('success' == result) {
				queryTask_task();
			} else {
				new $.Zebra_Dialog('操作失败，请刷新页面再次尝试，如果问题依然存在，请联系管理员!', {
				    'buttons':  false,
				    'modal': false,
				    'position': ['right - 20', 'top + 20'],
				    'auto_close': 2000
				});
			}
		}
	});
}

function aidExecuteTransfer_task(code, url) {
	var parm = {'code':code};
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if ('success' == result) {
				queryTransfer_task();
			} else {
				new $.Zebra_Dialog('操作失败，请刷新页面再次尝试，如果问题依然存在，请联系管理员!', {
				    'buttons':  false,
				    'modal': false,
				    'position': ['right - 20', 'top + 20'],
				    'auto_close': 2000
				});
			}
		}
	});
}

function shieldTask_task(code, title) {
	$.Zebra_Dialog('确定是否屏蔽'+title + ' 移交内容吗？',{
	'type': 'question',
	'title': '警告' ,
	'buttons':[
	           {caption:'屏蔽',callback:function() {
	        	   var url = create_url('task-shield');
	        	   aidExecuteTransfer_task(code, url);
	    		}},
	           {caption:'取消',callback:function(){}
	    	}]
	});
}

function unshieldTask_task(code, title) {
	$.Zebra_Dialog('确定是否屏蔽'+title + ' 移交内容吗？',{
	'type': 'question',
	'title': '警告' ,
	'buttons':[
	           {caption:'屏蔽',callback:function() {
	        	   var url = create_url('task-unshield');
	        	   aidExecuteTransfer(code, url);
	    		}},
	           {caption:'取消',callback:function(){}
	    	}]
	});
}

/*************************************************edit********************************/

function saveTask_task() {
	var parm = $('#editTaskForm').serialize();
	var url = create_url('task-save');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if (result == 'success') {
				sys_msg('操作成功');
				sys_load_handle('task');
			}else if(result == 'not_find') {
				sys_msg('请填写内容', '警告');
			}else if(result == 'null_title') {
				sys_msg('请填写标题', '警告');
			}else if(result == 'null_time') {
				sys_msg('任务时间不能为空', '警告');
			}else if(result == 'null_user') {
				sys_msg('请选择办理人', '警告');
			}else {
				sys_msg('操作失败', '警告');
			}
		}
	});
}

function saveTransfer_task(){
	var parm = $('#editTransferForm').serialize();
	var url = create_url('task-saveTransfer');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if (result == 'success') {
				sys_msg('操作成功');
				sys_load_handle('task');
			} else {
				sys_msg('操作失败');
			}
		}
	});
}


function saveTaskShow_task() {
	var parm = $('#editTaskShowForm').serialize();
	var url = create_url('task-save');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm,
		success: function(result) {
			sys_submiting_close();
			if (result == 'success') {
				sys_msg('操作成功');
				sys_load_handle('task');
			}else if(result == 'not_update'){
				sys_msg('该任务已完成不可修改');
			} else {
				sys_msg('操作失败');
			}
		}
	});
}

function editTransfer_task(code) {
	var parm = {'mc': code};
	var url = create_url('task-editTransfer');
	sys_submiting();
	$.ajax({type:'POST', url:url, data:parm});
}
